package logic

import (
	"context"
	"gorm.io/gorm"
	"shuqi-novel/model"

	"shuqi-novel/shuqirpc/internal/svc"
	"shuqi-novel/shuqirpc/shuqirpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddNovelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddNovelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddNovelLogic {
	return &AddNovelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddNovelLogic) AddNovel(in *shuqirpc.AddNovelRequest) (*shuqirpc.AddNovelResponse, error) {
	// todo: add your logic here and delete this line
	var novel model.Novel
	novel = model.Novel{
		Model:  gorm.Model{ID: uint(in.NovelId)},
		Title:  in.Title,
		Image:  in.Image,
		UserId: int(in.UserId),
	}
	model.DB.Updates(&novel)
	return &shuqirpc.AddNovelResponse{
		NovelId: int64(novel.ID),
	}, nil
}
